<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>nav</title>
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <nav class="my-menu">
    <ul>
      <li class="my-menu-item">最新活动</li>
      <li class="my-menu-item">产品</li>
      <li class="my-menu-item">大数据</li>
      <span class="my-menu-select"></span>
    </ul>
  </nav>
  <script>
    var menu = document.querySelector('ul');
    menu.addEventListener('mouseenter', mouseenter);
    menu.addEventListener('mouseout', mouseout);

    function mouseenter(e) {
      var ele = e.target,
          selectedItem = document.querySelector('.my-menu-selected');

      console.log('enter', ele.nodeName.toLowerCase());
      if(ele.nodeName.toLowerCase() == 'li') { 
        var domRect = ele.getBoundingClientRect();
        var o = {
          'width': domRect.width + 'px',
          'left':  domRect.left + 'px'
        } 
        setStyle(selectedItem, o);
      }
    }

    function mouseout(e) {
      console.log('out', e.target);
    }

    function setStyle(ele, styleObj) {
      for(var style in styleObj) {
        ele.style[style] = styleObj[style];
      }
    }
  </script>
</body>
</html>